home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Online / SpeakFreely / src / libdes / doPC2 < prev    next >
Text File  |  2000-05-18  |  2KB  |  95 lines

  1. #!/usr/local/bin/perl
  2.  
  3. @PC2_C=(14,17,11,24, 1, 5,
  4.      3,28,15, 6,21,10,
  5.     23,19,12, 4,26, 8,
  6.     16, 7,27,20,13, 2,
  7.     );
  8.  
  9. @PC2_D=(41,52,31,37,47,55,
  10.     30,40,51,45,33,48,
  11.     44,49,39,56,34,53,
  12.     46,42,50,36,29,32,
  13.     );
  14.  
  15. $i=0;
  16. foreach (@PC2_C) {
  17.     $_--;
  18. #    printf "%2d,",$_;
  19.     $C{$_}=$i;
  20.     ++$i;
  21. #    print "\n" if ((($i) % 8) == 0);
  22.     }
  23. $i=0;
  24. #print "\n";
  25. foreach (@PC2_D) {
  26.     $_-=28;
  27.     $_--;
  28. #    printf "%2d,",$_;
  29.     $D{$_}=$i;
  30.     $i++;
  31. #    print "\n" if ((($i) % 8) == 0);
  32.     }
  33.  
  34. #print "\n";
  35. foreach $i (0 .. 27)
  36.     {
  37.     $_=$C{$i};
  38. #    printf "%2d,",$_;
  39.     $i++;
  40. #    print "\n" if ((($i) % 8) == 0);
  41.     }
  42. #print "\n";
  43.  
  44. #print "\n";
  45. foreach $i (0 .. 27)
  46.     {
  47.     $_=$D{$i};
  48. #    printf "%2d,",$_;
  49.     $i++;
  50. #    print "\n" if ((($i) % 8) == 0);
  51.     }
  52. #print "\n";
  53.  
  54. print "static ulong skb[8][64]={\n";
  55. &doit("C",*C, 0, 1, 2, 3, 4, 5);
  56. &doit("C",*C, 6, 7, 9,10,11,12);
  57. &doit("C",*C,13,14,15,16,18,19);
  58. &doit("C",*C,20,22,23,25,26,27);
  59.  
  60. &doit("D",*D, 0, 1, 2, 3, 4, 5);
  61. &doit("D",*D, 7, 8,10,11,12,13);
  62. &doit("D",*D,15,16,17,18,19,20);
  63. &doit("D",*D,21,22,23,24,26,27);
  64. print "};\n";
  65.  
  66. sub doit
  67.     {
  68.     local($l,*A,@b)=@_;
  69.     local(@out);
  70.  
  71.     printf("/* for $l bits (numbered as per FIPS 46) %d %d %d %d %d %d */\n",
  72.         $b[0]+1, $b[1]+1, $b[2]+1, $b[3]+1, $b[4]+1, $b[5]+1);
  73.     for ($i=0; $i<64; $i++)
  74.         {
  75.         $out[$i]=0;
  76.         $j=1;
  77. #print "\n";
  78.         for ($k=0; $k<6; $k++)
  79.             {
  80.             $l=$A{$b[$k]};
  81. #print"$l - ";
  82.             if ((1<<$k) & $i)
  83.                 {
  84.                 $ll=int($l/6)*8+($l%6);
  85.                 $out[$i]|=1<<($ll);
  86.                 }
  87.             }
  88.         $pp=$out[$i];
  89.         $pp=($pp&0xff0000ff)|   (($pp&0x00ff0000)>>8)|
  90.                     (($pp&0x0000ff00)<<8);
  91.         printf("0x%08X,",$pp);
  92.         print "\n" if (($i+1) % 4 == 0);
  93.         }
  94.     }
  95.